package action.admin.feedback;

import dao.FeedBackDAO;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(name = "editFeedBack", urlPatterns = {"/editFeedBack"})
public class editFeedBack extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        try {
            String action = request.getParameter("action");
            if (action.equals("delete")) {
                String feedback_id = request.getParameter("feedback_id");
                String msg = "";
                String error = "";
                FeedBackDAO fbDAO = new FeedBackDAO();
                if (fbDAO.deleteFeedBack(feedback_id)) {
                    msg = "Delete Successfull !";
                } else {
                error = "Delete Error !";
                }
                request.setAttribute("error", error);
                request.setAttribute("msg", msg);
                RequestDispatcher rd = request.getRequestDispatcher("index.jsp?page=feedback");
                rd.forward(request, response);
            } else if (action.equals("update")) {                    
                String feedback_id = request.getParameter("feedback_id");
                String acc_id = request.getParameter("acc_id");
                String question = request.getParameter("question");
                String answer = request.getParameter("answer");
                String class_id = request.getParameter("class_id");
                request.setAttribute("feedback_id", feedback_id);
                request.setAttribute("acc_id", acc_id);
                request.setAttribute("question", question);
                request.setAttribute("answer", answer);
                request.setAttribute("class_id", class_id);
                RequestDispatcher rd = request.getRequestDispatcher("index.jsp?page=update_FeedBack");
                rd.forward(request, response);
            } else if (action.equals("show_by_class")) {
                String class_id = request.getParameter("class_id");
                request.setAttribute("class_id", class_id);
                RequestDispatcher rd = request.getRequestDispatcher("index.jsp?page=feedback");
                rd.forward(request, response);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}
